*************************************************************************************
*****			Please cite Georgiadou et al. (2018) as indicated in 			*****
*****  	https://www.sciencedirect.com/science/article/pii/S026137941830026X		*****
*************************************************************************************



use Data/GRR_data.dta, clear
cd Graphs
***** Original code from Golder (2003), adapted for our regressions
gen _Zero = 0
 
*******************
*   Figure 5 a    *
*******************
*** run regression obtain coefficients
pantob radical_right Lunemp Ldiff_immigration Lunemp_diffimmigration Lgdp_pps_hab Ltax Lgini  Lwage_sh LD_gdp_growth    D_par  nuts_2 

*** get variance-covariance matrix
estat vce
generate JH=((_n-1)/1000)    
replace JH=. if _n>250

generate str1 txt="*"

scalar b1=2.482077
scalar b2= .532918
scalar b3=6.841585

scalar varb1=.1140236
scalar varb3= 570.63008
scalar covb1b3=2.4518313

set more off
scalar list b1 b2 b3 varb1 varb3 covb1b3

*     ****************************************************************  *
*      Except for in left hand side of following, do search and replace *
*      for JH below                                                     *
*     ****************************************************************  *

gen conb=b1+b3*JH if _n<260
set more off
list conb in 1/20

*     ****************************************************************  *
*      These create conditional coefficients for b1 at JH, x3H#         *
*     ****************************************************************  *
*      We can write the following code as a template, then sub in the   *
*      names of the "variables" for JH *x3 .   "variables" because they *
*      won't be the real variables.  Instead, they'll be the variables  *
*      created to represent the relevant values of the modifying        *
*      variables.                                                       *
*     ****************************************************************  *

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<260
set more off
list conse in 1/20
gen cont= conb/conse
list cont in 1/20

*     ****************************************************************  *
*      This creates a conditional t for each level of JHHH given which  *
*      x3H is chosen                                                    *
*     ****************************************************************  *

gen conbS = conb

*     ****************************************************************  *
*       These create "shadow" (thus the "S") variables for each of the  *
*       conditional b's.  Statistical significance indicated at 95%     *
*       level (one-tailed).                                             *
*     ****************************************************************  *

replace conbS = . if abs(cont)<1.645

list conbS in 1/20

*     ****************************************************************  *
*      This creates missing values for all the insignificant shadow b's.*
*     ****************************************************************  *
*     ****************************************************************  *
*     ****************************************************************  *
*       Generate confidence intervals at the 95% level                  *
*     ****************************************************************  *
*     ****************************************************************  *

gen a=1.645*conse
gen top=conb+a
gen bottom=conb-a

set textsize 100

*     ****************************************************************  *
*       Graph the effect of Immigration  on Voteshare conditional on    *
*       Unemployment                                                    *
*     ****************************************************************  *
gprefs set window scheme blackbg
gprefs set window update
gprefs set custom1 pen2_thick 9


*twoway line conb JH, lcolor(black) || line  top  JH, lcolor(black) lpattern(longdash)|| line  bottom JH, lcolor(black) lpattern(longdash) graphregion(color(white))  legend(off) xtitle("Immigration flow", size(medlarge)) ytitle("Effect of unemployment on PRR vote", size(medlarge))

twoway rarea bottom top JH, color(gs12) fcolor(gs12) graphregion(color(white))  legend(off) xtitle("Immigration flow",  size(medlarge)) ytitle("Effect of unemployment on PRR vote", size(small)) saving(figure5a,replace) || line conb JH, lcolor(black) || line _Zero JH, lcolor(black) lpattern(dash) lwidth(med)  


drop JH txt conb conse cont conbS a top bottom










*******************
*   Figure 5 b    *
*******************

generate JH=((_n-1)/1000)    
replace JH=. if _n>250
generate str1 txt="*"


scalar b1= .532918
scalar b2= 2.482077  
scalar b3= 6.841585 
scalar varb1=.36600357
scalar varb3=570.63008
scalar covb1b3= -12.496373

set more off
scalar list b1 b2 b3 varb1 varb3 covb1b3

*     ****************************************************************  *
*      Except for in left hand side of following, do search and replace *
*      for JH below                                                     *
*     ****************************************************************  *

gen conb=b1+b3*JH if _n<260
set more off
list conb in 1/20

*     ****************************************************************  *
*      These create conditional coefficients for b1 at JH, x3H#         *
*     ****************************************************************  *
*      We can write the following code as a template, then sub in the   *
*      names of the "variables" for JH *x3 .   "variables" because they *
*      won't be the real variables.  Instead, they'll be the variables  *
*      created to represent the relevant values of the modifying        *
*      variables.                                                       *
*     ****************************************************************  *
gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<260
set more off
list conse in 1/20
gen cont= conb/conse
list cont in 1/20

*     ****************************************************************  *
*      This creates a conditional t for each level of JHHH given which  *
*      x3H is chosen                                                    *
*     ****************************************************************  *
gen conbS = conb

*     ****************************************************************  *
*       These create "shadow" (thus the "S") variables for each of the  *
*       conditional b's.  Statistical significance indicated at 95%     *
*       level (one-tailed).                                             *
*     ****************************************************************  *
replace conbS = . if abs(cont)<1.645
list conbS in 1/20

*     ****************************************************************  *
*      This creates missing values for all the insignificant shadow b's.*
*     ****************************************************************  *
*     ****************************************************************  *
*     ****************************************************************  *
*       Generate confidence intervals at the 95% level                  *
*     ****************************************************************  *
*     ****************************************************************  *

gen a=1.645*conse
gen top=conb+a
gen bottom=conb-a
set textsize 100

*     ****************************************************************  *
*       Graph the effect of Immigration  on Voteshare conditional on    *
*       Unemployment                                                    *
*     ****************************************************************  *
gprefs set window scheme blackbg
gprefs set window update
gprefs set custom1 pen2_thick 9


*twoway line conb JH, lcolor(black) || line  top  JH, lcolor(black) lpattern(longdash)|| line  bottom JH, lcolor(black) lpattern(longdash) graphregion(color(white))  legend(off) xtitle("Unemployment", size(medlarge)) ytitle("Effect of immigration flow on PRR vote", size(medlarge))

twoway rarea bottom top JH, color(gs12) fcolor(gs12) graphregion(color(white))  legend(off) xtitle("Unemployment",  size(medlarge)) ytitle("Effect of immigration flow on PRR vote", size(small)) saving(figure5b,replace)|| line conb JH, lcolor(black) || line _Zero JH, lcolor(black) lpattern(dash) lwidth(med) 


drop JH txt conb conse cont conbS a top bottom






*******************
*   Figure 5 c    *
*******************
*** run regression obtain coefficients
pantob ext_right_cat1 Lunemp Ldiff_immigration Lunemp_diffimmigration Lgdp_pps_hab Ltax Lgini  Lwage_sh LD_gdp_growth    D_par  nuts_2 
*** get variance-covariance matrix

estat vce

generate JH=((_n-1)/1000)    
replace JH=. if _n>250
generate str1 txt="*"

scalar b1=1.286568
scalar b2= -.460439
scalar b3= 22.40538 
scalar varb1=.12825404 
scalar varb3= 149.50974
scalar covb1b3=.78766084

set more off
scalar list b1 b2 b3 varb1 varb3 covb1b3

*     ****************************************************************  *
*      Except for in left hand side of following, do search and replace *
*      for JH below                                                     *
*     ****************************************************************  *

gen conb=b1+b3*JH if _n<260
set more off
list conb in 1/20

*     ****************************************************************  *
*      These create conditional coefficients for b1 at JH, x3H#         *
*     ****************************************************************  *
*      We can write the following code as a template, then sub in the   *
*      names of the "variables" for JH *x3 .   "variables" because they *
*      won't be the real variables.  Instead, they'll be the variables  *
*      created to represent the relevant values of the modifying        *
*      variables.                                                       *
*     ****************************************************************  *

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<260
set more off
list conse in 1/20
gen cont= conb/conse
list cont in 1/20

*     ****************************************************************  *
*      This creates a conditional t for each level of JHHH given which  *
*      x3H is chosen                                                    *
*     ****************************************************************  *

gen conbS = conb

*     ****************************************************************  *
*       These create "shadow" (thus the "S") variables for each of the  *
*       conditional b's.  Statistical significance indicated at 95%     *
*       level (one-tailed).                                             *
*     ****************************************************************  *

replace conbS = . if abs(cont)<1.645
list conbS in 1/20

*     ****************************************************************  *
*      This creates missing values for all the insignificant shadow b's.*
*     ****************************************************************  *
*     ****************************************************************  *
*     ****************************************************************  *
*       Generate confidence intervals at the 95% level                  *
*     ****************************************************************  *
*     ****************************************************************  *

gen a=1.645*conse
gen top=conb+a
gen bottom=conb-a
set textsize 100

*     ****************************************************************  *
*       Graph the effect of Immigration  on Voteshare conditional on    *
*       Unemployment                                                    *
*     ****************************************************************  *
gprefs set window scheme blackbg
gprefs set window update
gprefs set custom1 pen2_thick 9


twoway rarea bottom top JH, color(gs12) fcolor(gs12) graphregion(color(white))  legend(off) xtitle("Immigration flow",  size(medlarge)) ytitle("Effect of Unemployment on ER vote", size(small)) saving(figure5c,replace) || line conb JH, lcolor(black) || line _Zero JH, lcolor(black) lpattern(dash) lwidth(med) 

drop JH txt conb conse cont conbS a top bottom











*******************
*   Figure 5 d    *
*******************

generate JH=((_n-1)/1000)    
replace JH=. if _n>250
generate str1 txt="*"

scalar b1= -.460439
scalar b2= 1.286568
scalar b3= 22.40538
scalar varb1= .0908654
scalar varb3= 149.50974 
scalar covb1b3= -3.5431385

set more off

scalar list b1 b2 b3 varb1 varb3 covb1b3

*     ****************************************************************  *
*      Except for in left hand side of following, do search and replace *
*      for JH below                                                     *
*     ****************************************************************  *

gen conb=b1+b3*JH if _n<260
set more off
list conb in 1/20

*     ****************************************************************  *
*      These create conditional coefficients for b1 at JH, x3H#         *
*     ****************************************************************  *
*      We can write the following code as a template, then sub in the   *
*      names of the "variables" for JH *x3 .   "variables" because they *
*      won't be the real variables.  Instead, they'll be the variables  *
*      created to represent the relevant values of the modifying        *
*      variables.                                                       *
*     ****************************************************************  *


gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<260
set more off
list conse in 1/20
gen cont= conb/conse
list cont in 1/20

*     ****************************************************************  *
*      This creates a conditional t for each level of JHHH given which  *
*      x3H is chosen                                                    *
*     ****************************************************************  *

gen conbS = conb

*     ****************************************************************  *
*       These create "shadow" (thus the "S") variables for each of the  *
*       conditional b's.  Statistical significance indicated at 95%     *
*       level (one-tailed).                                             *
*     ****************************************************************  *

replace conbS = . if abs(cont)<1.645
list conbS in 1/20

*     ****************************************************************  *
*      This creates missing values for all the insignificant shadow b's.*
*     ****************************************************************  *
*     ****************************************************************  *
*     ****************************************************************  *
*       Generate confidence intervals at the 95% level                  *
*     ****************************************************************  *
*     ****************************************************************  *

gen a=1.645*conse
gen top=conb+a
gen bottom=conb-a
set textsize 100

*     ****************************************************************  *
*       Graph the effect of Immigration  on Voteshare conditional on    *
*       Unemployment                                                    *
*     ****************************************************************  *
gprefs set window scheme blackbg
gprefs set window update
gprefs set custom1 pen2_thick 9


*twoway line conb JH, lcolor(black) || line  top  JH, lcolor(black) lpattern(longdash)|| line  bottom JH, lcolor(black) lpattern(longdash) graphregion(color(white))  legend(off) xtitle("Unemployment", size(medlarge)) ytitle("Effect of immigration flow on ER vote", size(medlarge))

twoway rarea bottom top JH, color(gs12) fcolor(gs12) graphregion(color(white))  legend(off) xtitle("Unemployment",  size(medlarge)) ytitle("Effect of immigration flow on ER vote", size(small)) saving(figure5d,replace)|| line conb JH, lcolor(black) || line _Zero JH, lcolor(black) lpattern(dash) lwidth(med) 

drop JH txt conb conse cont conbS a top bottom


gr combine figure5a.gph figure5b.gph figure5c.gph figure5d.gph, graphregion(color(white))
graph save ../Graphs/Figure5.gph, replace
graph export ../Graphs/Figure5.pdf, replace

cd ..

